<template>
  <div class="WorkingSchedule" v-loading="loading">
    <el-form ref="form" :model="form" label-position="top" class="myform">
      <div>
        <el-form-item label="工厂名:" class="myform-item">
          <el-input v-model="form.factory_name" placeholder="请输入工厂名" clearable></el-input>
        </el-form-item>
        <el-form-item label="SKU:" class="myform-item">
          <el-input v-model="form.sku_code" placeholder="请输入SKU" clearable></el-input>
        </el-form-item>
        <el-form-item label="加工单:" class="myform-item">
          <el-input v-model="form.processing_code" placeholder="请输入加工单" clearable></el-input>
        </el-form-item>
        <el-form-item label="确认状态:" class="myform-item">
          <el-select v-model="form.m_status" placeholder="请选择" clearable>
            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="推送状态:" class="myform-item">
          <el-select v-model="form.push_jw_status" placeholder="请选择" clearable>
            <el-option v-for="item in optionsts" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </div>
      <div>
        <el-form-item style="margin-top: 50px">
          <el-button type="primary" @click="onSearch">查询</el-button>
        </el-form-item>
      </div>
    </el-form>
    <el-table :data="tableData" style="width: 100%" border @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column label="成品加工单号" align="center" prop="processing_code">
      </el-table-column>
      <el-table-column label="状态" align="center" prop="m_status">
        <template slot-scope="{ row }">
          <div :style="{ color: row.m_status != 0 ? '#2c70d6' : '' }">
            {{ row.m_status == 0 ? "未确认" : "已确认" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="工厂" align="center" prop="factory_name">
      </el-table-column>
      <el-table-column label="SKU" align="center" prop="sku_code">
      </el-table-column>
      <el-table-column label="品名" align="center" prop="product_name">
      </el-table-column>
      <el-table-column label="款名" align="center" prop="type_name">
      </el-table-column>
      <el-table-column label="执行标准" align="center" prop="executive_standard">
      </el-table-column>
      <el-table-column label="安全类别" align="center" prop="safety_category">
      </el-table-column>
      <el-table-column label="理单员" align="center" prop="order_processor">
      </el-table-column>
      <el-table-column label="数量" align="center" prop="num">
      </el-table-column>
      <el-table-column label="推送状态" align="center" prop="push_jw_status">
        <template slot-scope="{ row }">
          <div :style="{ color: row.push_jw_status == 0 ? '' : '#67C23A' }">
            {{ row.push_jw_status == 0 ? "未推送" : "已推送" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="{ row }">
          <el-button type="text" @click="onPush([row.m_id])" v-if="row.push_jw_status == 0" size="mini">推送</el-button>
          <el-button type="text" size="default" v-if="row.m_status == 0" @click="onAffirm(0, row.m_id)">确认</el-button>
          <el-button type="text" style="color: #67c23a" v-if="row.m_status != 0" size="default"
            @click="onPreview(row.m_id)">预览</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-button size="default" type="primary" :disabled="!multipleSelection.length" @click="onAffirm(1)"
      style="margin-top: 20px">批量确认</el-button>
    <el-button size="default" type="primary" :disabled="!multipleSelection.length" @click="onPushAll"
      style="margin-top: 20px">批量推送</el-button>
    <pagination :form="form" :total="total" @paginationPostOrderTaskList="postAdminCodeGetProcessingTagList" />
    <el-dialog title="吊牌" :visible.sync="dialogVisible" width="30%" :before-close="handleClose" v-if="dialogVisible">
      <div style="
          border: 1px solid #000;
          border-radius: 6mm;
          background: #fff;
          width: 46mm;
          height: 131mm;
        ">
        <div class="tags" id="tages">
          <div class="tags-one"></div>
          <div class="tags-one1">合格证</div>
          <div class="tags-one2">品牌：{{ dataDP.brand_name }}</div>
          <div class="tags-one2">品名：{{ dataDP.product_name }}</div>
          <div class="tags-one2">款号：{{ dataDP.type_no }}</div>

          <div class="tags-one3">
            <span>{{ dataDP.fabric }}</span>
          </div>
          <div class="tags-one2">执行标准：{{ dataDP.executive_standard }}</div>
          <div class="tags-one4">
            <div>
              <div>安全类别：</div>
              <div>{{ dataDP.safety_category }}</div>
            </div>
            <div>
              <div>等级：</div>
              <div>合格品</div>
            </div>
             <div>
              <div>检验员：</div>
              <div>{{ dataDP.tag_number }}</div>
            </div>
          </div>
          <div style="height: 16mm;"></div>
          <div class="tags-one5" style="margin-top: 2mm">
            公司:{{ dataDP.company_head }}
          </div>
          <div class="tags-one5">电话:{{ dataDP.company_tel }}</div>
          <div class="tags-one5">
            地址:
            {{ dataDP.address }}
          </div>
          <div class="tags-one6" v-if="dataDP.code_list && dataDP.code_list.size_code">
            {{ dataDP.code_list.size_code.title }}
            <span style="margin-left:5px;font-weight:400;font-size: 2.3mm;
    zoom: 0.7;">{{ dataDP.specifications_base_cdoe }}</span>
          </div>
          <div class="tags-one7">
            <span v-if="dataDP.code_list && dataDP.code_list.height_code.title">
                {{ dataDP.code_list.height_code.title }}/{{dataDP.code_list.waist_code.title }}
            </span>
              <span v-if="dataDP.is_tz" style="font-size: 3mm;margin-left: 17mm">吊牌价：¥ {{dataDP.tag_price}}</span>
          </div>
          <img id="barcode" style="width: 36mm; height: 10mm" />
          <div class="tags-one8">
            <span>{{ dataDP.sku_code }}</span>
          </div>
          <div class="tags-one9" v-if="['十三余','锦瑟'].includes(dataDP.brand_name)">
              <img v-if="dataDP.brand_name=='十三余'" src="../../../assets/images/wxqrcod.png" alt="" />
              <img v-if="dataDP.brand_name=='锦瑟'" src="../../../assets/images/wxqrcode_js.png" alt="" />
            <div class="tags-one9-two">
              <div>
                <img src="../../../assets/images/wx.png" alt="" />
                <div>微信扫一扫</div>
              </div>
              <div>微信扫描防伪小程序，鉴定产品真伪。</div>
              <div>认准正品，谨防假冒</div>
            </div>
          </div>
        </div>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" v-print="'#tages'">打 印</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  postAdminCodeGetProcessingTagList,
  postAdminCodesetProcessingTagList,
  postAdminCodeGetTagLook_preview,
  postAdminOmsaddWarehousingProcessing,
  postAdminOmsPushProjw
} from "@/api";
import pagination from "@/components/pagination.vue";
import JsBarcode from "jsbarcode";
export default{
  components: { pagination },
  data() {
    return {
      loading: false,
      dialogVisible: false,
      dataDP: "",
      options: [
        {
          value: 0,
          label: "未确认",
        },
        {
          value: 1,
          label: "已确认",
        },
      ],
      optionsts: [
        {
          value: 0,
          label: "未推送",
        },
        {
          value: 1,
          label: "已推送",
        },
      ],
      multipleSelection: [],
      form: {
        factory_name: "",
        sku_code: "",
        processing_code: "",
        m_status: "",
        push_jw_status: "",
        page: 1,
        size: 10,
      },
      tableData: [],
      total: 1,
    };
  },
  activated() {
    let form = this.form;
    this.postAdminCodeGetProcessingTagList(form);
  },
  methods: {
    // 批量推送
    onPushAll() {
      let { multipleSelection } = this
      let ids = []
      for (let index = 0; index < multipleSelection.length; index++) {
        const element = multipleSelection[index];
        ids.push(element.m_id)
      }
      this.onPush(ids)
    },
    // 推送
    onPush(ids) {
      let obj = {
        ids,
      };
      let form = this.form;
      this.$confirm(`确定推送?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          postAdminOmsPushProjw(obj).then((res) => {
            this.$message({
              type: "success",
              message: "成功",
            });
            this.postAdminCodeGetProcessingTagList(form);
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消推送",
          });
        });
    },
    async onPreview(id) {
      let obj = {
        id,
      };
      let res = await postAdminCodeGetTagLook_preview(obj);
      let data = res.data;
      this.dataDP = data;

      this.dialogVisible = true;
      this.$nextTick(() => {
        // 待生成条码的内容
        JsBarcode("#barcode", data.sku_code, {
          displayValue: false,
        });
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 确认
    onAffirm(type, id) {
      let ids = [];
      if (type == 0) {
        ids.push(id);
      } else {
        let multipleSelection = this.multipleSelection;
        multipleSelection.forEach((res) => {
          ids.push(res.m_id);
        });
      }
      let obj = {
        ids,
      };
      this.$confirm("确认吊牌?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        postAdminCodesetProcessingTagList(obj).then((res) => {
          let form = this.form;
          this.postAdminCodeGetProcessingTagList(form);
          this.$message({
            type: "success",
            message: "确认成功!",
          });
        });
      });
    },
    // 采购列表
    async postAdminCodeGetProcessingTagList(data) {
      this.loading = true;
      this.form = data;
      postAdminCodeGetProcessingTagList(data)
        .then((res) => {
          this.loading = false;
          console.log("采购列表", res);
          this.tableData = res.data;
          this.total = Number(res.total);
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 搜索
    onSearch() {
      this.form.page = 1;
      this.form.size = 10;
      this.postAdminCodeGetProcessingTagList(this.form);
    },
  },
};
</script>

<style lang="scss" scoped>
.tags {
  background: #fff;
  width: 45mm;
  height: 130mm;
  // border: 1px solid #000;
  border-radius: 6mm;
  color: #000;
  padding: 0 3mm;
  box-sizing: border-box;

  .tags-one {
    width: 4mm;
    height: 4mm;
    border-radius: 4mm;
    // border: 0.1mm solid #999;
    height: 11mm;
  }

  .tags-one1 {
    font-size: 3.6mm;
    font-weight: 600;
    text-align: center;
  }

  .tags-one2 {
    font-size: 2.3mm;
    margin-top: 2mm;
    zoom: 0.73;
  }

  .tags-one3 {
    // height: 20mm;
    zoom: 0.7;
    font-size: 2mm;
    margin-top: 2mm;
    white-space: pre-line;
  }

  .tags-one4 {
    // display: flex;
    // margin-top: 1mm;

    // margin-top: 16mm;

    >div {
      display: flex;
      align-items: center;
      margin-top: 2mm;
      >div:nth-child(1) {
        font-size: 2.3mm;
        zoom: 0.73;
      }

      >div:nth-child(2) {
        font-size: 2.3mm;
        zoom: 0.7;
      }
    }
  }

  .tags-one5 {
    font-size: 2.3mm;
    zoom: 0.7;
    margin-top: 1mm;
  }

  .tags-one6 {
    font-size: 3.6mm;
    font-weight: 600;
    margin-top: 0.8mm;
    margin-left: 2mm;
  }

  .tags-one7 {
    font-size: 2.3mm;
    zoom: 0.73;
    height: 4mm;
    margin-left: 2mm;
  }

  .tags-one8 {
    background: #ffff;
    width: 36mm;
    text-align: center;
    font-size: 2mm;
    margin-top: -2.2mm;

    >span {
      zoom: 0.73;
    }
  }

  .tags-one9 {
    margin-top: 1mm;
    display: flex;

    >img {
      width: 10mm;
      height: 10mm;
    }

    .tags-one9-two {
      margin-left: 2mm;

      >div:nth-child(1) {
        display: flex;
        align-items: center;

        >img {
          width: 4.3mm;
          height: 4.3mm;
          margin-right: 1mm;
        }

        >div {
          font-size: 2.3mm;
          zoom: 0.73;
        }
      }

      >div:nth-child(2) {
        margin-top: 1mm;
        font-size: 2.3mm;
        zoom: 0.48;
      }

      >div:nth-child(3) {
        font-size: 2.3mm;
        zoom: 0.48;
        margin-top: 1mm;
      }
    }
  }
}

.myform {
  display: flex;
  justify-content: space-between;

  >div {
    display: flex;
  }

  &-item {
    margin-right: 10px;
  }
}

.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
</style>
